﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeWeb;
using CMS.Channel;
using CMS.Model;
using CMSWCSFSolution.CMS.Interface.Services;
using CMS.ViewModel;

namespace CMSWCSFSolution.CMS.Views
{
    public class StudentMainPagePresenter : Presenter<IStudentMainPageView>
    {
        private int _rowCount;
        private ICMSService  _service;

        public StudentMainPagePresenter([CreateNew] ICMSService service)
        {
            _service = service;
        }
        /// <summary>
        /// Ons the select all students.
        /// </summary>
        public void onSelectAllStudents()
        {
             List<Student> student = _service.GetAllstudents(View.PageIndex, View.PageSize, out _rowCount); 
             List<StudentCourseDetailView> studentCourseDetailViewList = new List<StudentCourseDetailView>();
             StudentCourseDetailView studentCourseDetailView;
             foreach (Student obj in student)
             {
                 studentCourseDetailView = new StudentCourseDetailView();
                 studentCourseDetailView.ClassName = obj.Grade.ClassName;
                 studentCourseDetailView.StudentGender = obj.StudentGender;
                 studentCourseDetailView.StudentId = obj.StudentId;
                 studentCourseDetailView.StudentName = obj.StudentName;
                 studentCourseDetailViewList.Add(studentCourseDetailView);
             }
             View.BindStudentList= studentCourseDetailViewList;
             View.RowCount = _rowCount;
        }

        /// <summary>
        /// Called when [delete student by id].
        /// </summary>
        public void OnDeleteStudentById()
        {
            int studentId= View.StudentId;
            if (studentId != null)
            {
                _service.DeleteStudentById(studentId);
            }
        }
        public override void OnViewLoaded()
        {
        }
        public override void OnViewInitialized()
        {
        }
    }
}




